<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Consignment_management extends CI_Controller {

	 function __construct()
    {
        parent::__construct();
    }
	public function index()
	{
		$html=$this->init("代銷管理","jquery","table");
		$this->load->model('consignment_management_model');
		$html["consignment_management"]=$this->consignment_management_model->get_all();
		$this->load->view('consignment_management',$html);
	}
	
	public function add()
	{
		$html=$this->init("代銷管理添加","jquery","form");
		$this->load->view('consignment_management_add',$html);
	}

	public function add_submit()
	{
		$this->load->model('consignment_management_model');
		$data['consignment_name'] = $this->input->post('consignment_name');
		$data['explanation'] = $this->input->post('explanation');
		//$data['sequence'] = $this->input->post('sequence');
		$return_result=$this->consignment_management_model->add($data);
		//echo $this->db->last_query();die();
		if($return_result>0){
			redirect("/consignment_management");
		}else{
			echo "插入失敗";
		}
		
	}

	public function edit($id=null)
	{
		$html=$this->init("代銷管理編輯","jquery","form");
		$this->load->model('consignment_management_model');
		$html["consignment_management"]=$this->consignment_management_model->get_info($id);;
		$this->load->view('consignment_management_edit',$html);
	}
	public function edit_submit()
	{
		$this->load->model('consignment_management_model');
		$data['id']= $this->input->post('consignment_management_id');
		$data['consignment_name'] = $this->input->post('consignment_name');
		$data['explanation'] = $this->input->post('explanation');
		//print_r($data);die;
		//$data['sequence'] = $this->input->post('sequence');
		$return_result=$this->consignment_management_model->update_data($data);
		//echo $this->db->last_query();die();
		if($return_result){
			redirect("/consignment_management");
		}else{
			echo "編輯失敗";
		}
	
	}
	
	public function delete($id=null){
		$this->load->model('consignment_management_model');
		if($id!=null)
		{
			$data["id"]=$id;
			$return_result=$this->consignment_management_model->del($data);
			if($return_result){
				redirect("/consignment_management");
			}else{
				echo "刪除失敗";
			}
		}else{
			echo "刪除失敗";
		}	
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */